# regular  正则

import re # 导入re模块
text  = 'Python.C.Java...PHP'    # 定义text字符串
re.split('[.]+',text)    # 调用split()函数对text进行分割
re.findall('[a-zA-Z]+',text)     # 调用 findall()函数查找由大小写字母组成的字符串

test = '用户输入的字符串'
if re.match(r'正则表达式',test):
    print('ok')
else:
    print('failed')

# 匹配日期
text = '重要日期:2023-12-25, 2024-01-01'
dates = re.findall(r'\d{4}-\d{2}-\d{2}',text)
print(dates)    # 输出：[’2023-12-25','2024-01-01']

# 验证电子邮件地址
email = 'example@test.com'
is_valid = bool(re.match(r'^[\w\.-]+@[\w\.-]+\.\w+$',email))
print(is_valid)  # 输出：True

# 提取URL
text = '访问  https://example.com'
urls = re.findall(r'https?://\S+',text)
print(urls)    # 输出:['https://example.com']

# 匹配电话号码
phone = '(123) 456-7890'
is_phone = bool(re.match(r'\(\d{3}\)\s\d{3}-d{4}',phone))
print(is_phone)       # 输出True

